<?php

namespace app\api\model;

use app\common\model\BaseModel;

class User extends BaseModel
{
    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    /**
     * 获取用户信息
     */
    public static function getByField($whereField, $field)
    {
        return self::where($whereField, $field)->find();
    }

    /**
     * 绑定手机号
     */
    public static function bindMobile($openid, $mobile)
    {
        return self::where('wxapp_openid', $openid)->update(['mobile' => $mobile]);
    }

    /**
     * 用户信息
     */
    public static function getInfo($userId)
    {
        $field = ['user_id', 'nickname', 'avatar', 'mobile', 'money'];
        return self::field($field)->find($userId);
    }

    public static function getValueByField($userId, $field)
    {
        return self::where('user_id', $userId)->value($field);
    }
}
